﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;

namespace Ebada.Modules.Document
{
    public partial class frmDocumentbookEdit : FormBase, IPopupFormEdit 
    {
        public IList<Documents> list;
        public frmDocumentbookEdit()
        {
            InitializeComponent();
        }

        private void frmDocumentbookEdit_Load(object sender, EventArgs e)
        {
            UCDocumentsRight uc = new UCDocumentsRight();
            uc.Dock = DockStyle.Fill;
            uc.initColumns2();
            uc.hidebutton2();
            uc.List = list;
            splitContainerControl1.Panel2.Controls.Add(uc);
        }
        #region IPopupFormEdit Members
        private Documents rowData = null;

        public object RowData
        {
            get
            {
                return rowData;
            }
            set
            {
                if (value == null) return;
                if (rowData == null)
                {
                    this.rowData = value as Documents;
                    //dataBind();
                    //InitComboBoxData();
                }
                else
                {
                    ConvertHelper.CopyTo<Documents>(value as Documents, rowData);
                }
            }
        }

        #endregion

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            if (txtBookID.Text == "")
            {
                MessageBox.Show("册子编号不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtBookID.Focus();
                return;
            }
            else
            {
                IList<Documents> tempdoclist = MainHelper.PlatformSqlMap.GetList<Documents>(" where DocBookID='" + txtBookID.Text + "'");
                if (tempdoclist.Count>0)
                {
                    MessageBox.Show("["+txtBookID.Text +"]编号已存在！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtBookID.SelectAll();
                    txtBookID.Focus();
                    return ;
                }
            }
            if (txtBookName.Text == "")
            {
                MessageBox.Show("册子名称不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtBookName.Focus();
                return;
            }

            for (int i = 0; i < list.Count;i++ )
            {
                list[i].DocBookID = txtBookID.Text;
                list[i].DocBookName = txtBookName.Text;
                MainHelper.GetSqlMap<Documents>().Update<Documents>(list[i]);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
